
#include "../inc/StopWordList.h"



            StopWordList::StopWordList(char *fileName){
            	count=-1;
            	totalSize=INITIAL_SIZE;
            	words = new string[INITIAL_SIZE];
            	ifstream file;
            	file.open(fileName, ifstream::in);
            	//file.ignore(256,'\n');
            	while(!file.eof()){
            		char temp[256];
            		file.getline(temp,256);
            		string word= temp;
            		add(&word);
            	}
            }

            StopWordList::~StopWordList(){
            	delete[] words;
            }

            int compareStrs(const void * a, const void * b){
				string *A =(string *)a;
				string *B =(string *)b;
				return strcasecmp(A->c_str(),B->c_str());
			}

            bool StopWordList::contains(const string *word){

            	void  *ptr=bsearch(word, words, count ,sizeof(string),compareStrs);
            	return (ptr!=NULL);
            }

            void StopWordList::resize(){
            	totalSize= 2*totalSize;
            	string *temp=new string[totalSize];
            	for (int i=0;i<count;i++)
            		temp[i]=words[i];
            	delete[] words;
            	words=temp;
            }

            void StopWordList::add(const string *word){
            		count++;
            		if (count==totalSize)
            			resize();
            		words[count]=string(*word); //TODO scope?

            }


